package com.yuandian.management.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuandian.api.management.entity.ConfDataMaskConfig;
import com.yuandian.api.management.validate.InsertFlag;
import com.yuandian.bpm.common.core.util.R;
import com.yuandian.management.service.ConfDataMaskConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;
/**
 * 脱敏字段配置表-Controller
 * @author zfsn
 * @date 2023-6-7
 */
@Api(tags = "脱敏字段配置表功能接口")
@RestController
@RequestMapping("/dataMaskConfig")
public class ConfDataMaskConfigController {

	@Autowired
	private ConfDataMaskConfigService confDataMaskConfigService;

	/**
	 * 通过主键查询数据
	 * @param idList 主键集合
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "通过主键查询数据", notes = "通过主键查询数据，支持批量查询")
	@GetMapping("/{ids}")
	public R<List<ConfDataMaskConfig>> queryByIds(@PathVariable("ids") List<Integer> idList) {
		return R.ok(confDataMaskConfigService.listByIds(idList));
	}

	/**
	 * 分页查询
	 * @param confDataMaskConfig 分页对象
	 * @param confDataMaskConfig 筛选条件
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "分页查询", notes = "分页查询")
	@PostMapping
	@ApiImplicitParams({
			@ApiImplicitParam(name = "name", value = "列表脱敏字段(支持模糊查询)", paramType = "body", required = false, dataType = "String"),
			@ApiImplicitParam(name = "pageSize", value = "每页大小", paramType = "body", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "pageNum", value = "当前页数", paramType = "body", required = true, dataType = "Integer"),
	})
	public R<Page<ConfDataMaskConfig>> page(@RequestBody @ApiIgnore ConfDataMaskConfig confDataMaskConfig) {
		return R.ok(confDataMaskConfigService.listPage(confDataMaskConfig));
	}


	/**
	 * 通过主键更新数据
	 * @param confDataMaskConfig 实例对象
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "通过主键更新数据", notes = "通过主键更新数据")
	@PutMapping
	@ApiImplicitParams({
			@ApiImplicitParam(name = "id", value = "id", paramType = "body", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "name", value = "列表脱敏字段", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "code", value = "脱敏字段编码", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "startIndex", value = "脱敏开始位置", paramType = "body", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "length", value = "脱敏长度", paramType = "body", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "showFlag", value = "展示是否脱敏, 1:脱敏 0:不脱敏", paramType = "body", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "exportFlag", value = "导出是否脱敏, 1:脱敏 0:不脱敏", paramType = "body", required = true, dataType = "Integer"),
	})
	public R<String> updateById(@RequestBody @ApiIgnore @Validated({InsertFlag.class}) ConfDataMaskConfig confDataMaskConfig) {
		return confDataMaskConfigService.updateDataById(confDataMaskConfig);
	}


}